//
//  YHKBottomView.swift
//  xinlangweiBo2
//
//  Created by 杨和逵 on 16/3/2.
//  Copyright © 2016年 yanghekui. All rights reserved.
//

import UIKit

/**
 1.接口文档
 2.分析界面：三个按钮，两个线
 3.功能分析：展示评论或转发的属性，没哟评论和转发的时候显示文字
 */


class YHKBottomView: UIView {
    
   
    
    //定义一个模型来接收数据
    var homeCellViewModel:YHKHomeCellViewModel?{
        
        didSet{
        relayButton.setTitle("\(homeCellViewModel?.retweetString ?? "")", forState: UIControlState.Normal)
            
         commentButton.setTitle("\(homeCellViewModel?.commentsString ?? "")", forState: UIControlState.Normal)
            
        goodButton.setTitle("\(homeCellViewModel?.attitudesString ?? "")", forState: UIControlState.Normal)
        }
        
    }
    

//MARK创建视图三部曲
    
    //第一部init
   override init(frame: CGRect) {
        super.init(frame: frame)
      backgroundColor = UIColor.grayColor()
    setUpView()
    }

   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
    
    
    //第二部创建私有方法，添加控制器和设置约束
    private func setUpView(){
        
        //添加控件
        addSubview(relayButton)
        addSubview(commentButton)
        addSubview(goodButton)
        //线
        let lienRight = getLien()
        let lienLine  =  getLien()
        
        addSubview(lienLine)
        addSubview(lienRight)
        
        
        //设置约束
        //转发
        relayButton.snp_makeConstraints { (make) -> Void in
            //左 上 下 等宽
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            //注意
            make.width.equalTo(commentButton.snp_width)
            
        }
        
        //评论
        commentButton.snp_makeConstraints { (make) -> Void in
            //左右 上下
            make.left.equalTo(relayButton.snp_right)
            make.right.equalTo(goodButton.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
        }
        
        //点赞
        goodButton.snp_makeConstraints { (make) -> Void in
            //右 上 下 等宽
            make.right.equalTo(self.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            //注意
            make.width.equalTo(commentButton.snp_width)
        }
        
        
        //左线
        lienLine.snp_makeConstraints { (make) -> Void in
            //Y一样，X是边
            make.centerX.equalTo(relayButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        lienRight.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(goodButton.snp_left)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        
        
    }
    
    
    //懒加载
    //转发
    private lazy var relayButton:UIButton = {
    
   let relaybtn = UIButton(type: UIButtonType.Custom)
        
        relaybtn.setTitle("转发", forState: UIControlState.Normal)
        
        relaybtn.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        relaybtn.setTitleColor(UIColor(white: 0.95, alpha:1), forState: UIControlState.Normal)
        
    return relaybtn
    
    }()
    
    //评论
    private lazy var commentButton:UIButton = {
    
    let commentBtn = UIButton(type: UIButtonType.Custom)
        
        commentBtn.setTitle("评论", forState: UIControlState.Normal)
        
        commentBtn.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        commentBtn.setTitleColor(UIColor(white: 0.95, alpha: 1), forState: UIControlState.Normal)
        
    return commentBtn
    
    }()
    
    //点赞
    private lazy var goodButton:UIButton = {
    
    let goodBtn = UIButton(type: UIButtonType.Custom)
        
        goodBtn.setTitle("点赞", forState: UIControlState.Normal)
        
        goodBtn.setTitleColor(UIColor(white: 0.95, alpha: 1), forState: UIControlState.Normal)
        
        goodBtn.setImage(UIImage(named: "timeline_icon_like"), forState: UIControlState.Normal)
        
        return goodBtn
    
    }()
    
    //线
    private func getLien() -> UIImageView{
        
        return UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
        
    }
}
